use serde::Deserialize;
use serde::Serialize;
use ts_rs::TS;
use yata::core::PeriodType;
use yata::core::ValueType;

use super::IndicatorActionWrap;

///
/// Struct to hold the results of Struct yata::indicators::ChandeMomentumOscillator
///
///  参见[CMO](https://www.investopedia.com/terms/c/chandemomentumoscillator.asp)
///
#[derive(Serialize, Deserialize, Default, Debug, TS, Clone)]
#[ts(export)]
pub struct CMO {
    /// 1 signal
    /// When oscillator value goes above zone, then returns full sell signal.
    ///  When oscillator value goes below -zone, then returns full buy signal.
    /// Otherwise no signal
    pub signal0: Option<IndicatorActionWrap>,

    /// 1 value
    /// oscillator value
    /// Range in [-1.0; 1.0]
    pub oscillator: ValueType,
}

/// Configuration for  Struct yata::indicators::ChandeMomentumOscillator
#[derive(Serialize, Deserialize, Debug, TS, Clone, Copy)]
#[ts(export)]
pub struct CMOConfig {
    ///period: PeriodType
    ///main period length. Default is 9.
    ///
    ///Range in [2; PeriodType::MAX]
    pub period: PeriodType,
    /// zone: ValueType
    /// Zone size of overbought and oversold. Default is 0.5.
    ///
    /// Range in [0.0; 1.0]
    pub zone: ValueType,
    // pub source: Source,
}

impl Default for CMOConfig {
    fn default() -> Self {
        Self {
            period: 9,
            zone: 0.5,
        }
    }
}
